#include <iostream>
using namespace std;

int Rlcf(int n, int m)
{
	if (n < m)
	{
		int t = m;
		m = n;
		n = t;
	}
	if (m != 0)
	{
		return Rlcf(m, n%m);
	}
	else
	{
		return n;
	}
}

int Ilcf(int n, int m)
{
	if (n < m)
	{
		int t = m;
		m = n;
		n = t;
	}
	while (m != 0)
	{
		int t = m;
		m = n%m;
		n = t;
	}
	return n;
}

int main()
{
	cout << Rlcf(1071, 462) << endl;
	cout << Ilcf(1071, 462) << endl;
	cout << Rlcf(462, 1071) << endl;
	cout << Ilcf(462, 1071) << endl;

	system("pause");
	return 0;
}